#include"myname_pipe.hpp"


int main(){
    bool ret = creatfifo(PATH_NAME);
    assert(ret);
    (void)ret;

    //server用来读取客户端的数据
    int fp = open(PATH_NAME,O_RDONLY);
    if(fp < 0) exit(1);


    //一直读取
    while(true){
        char buffer[1024];
        ssize_t s = read(fp,buffer,sizeof(buffer)-1);
        if(s > 0){
            buffer[s] = 0;
            cout<<"# "<<buffer<<endl;
        } 
        else if(s == 0){
            cout<<"缓冲区的数据读取完了"<<endl;
            break;
        }
        
    }
    



    close(fp);
    //cout<<"fp:"<<fp<<endl;

    sleep(10);
    removefifo(PATH_NAME);
    return 0;
}